<template>
	<view :class="[config.style]">
		<view class="main-section tabbar-bottom">
			<view class="header">
	
				<view class="login" v-if="!userInfo.memberInfo" @click="login()">
					<view class="avatar">
						<image class="image" src="../../../static/images/user_default.png"></image>
					</view>
					<view class="login-btn">
						立即登录
					</view>
				</view>
				<view class="user-info" v-else>
					<view class="avatar">
						<image class="image" :src="userInfo.memberInfo.avatar"></image>
					</view>
					<view class="right-info">
						<view class="nickname">
					     {{userInfo.memberInfo.nickname}}
						</view>
						<view class="uid">
							UID：{{userInfo.memberInfo.uid}}
						</view>
					</view>
				</view>
				<view class="user-exp-info">
				<view class="wallet">
					<view class="info">
						<text class="credit" v-if="userInfo.memberInfo!==undefined">{{userInfo.memberInfo.credit2}}</text>
						<text class="credit">元</text>
					</view>
					<view class="title">钱包</view>
				</view>
				<view class="checkin" @click="navigateTo('../checkin/checkin')">
					
					<view class="info"> 
						<text class="credit" v-if="userInfo.memberInfo!==undefined">{{userInfo.memberInfo.credit1}}</text>
						<text class="credit">积分</text>
					</view>
					<view class="title">积分</view>
				</view>
			</view>
			</view>
			<view class="myOrder">
				<view class="indentbar ">
					<view class="part"></view>
					<view class="indent">我的活动</view>
					<view class="allorders" @click="navigateTo('activity/lists')">
						查看全部活动
					</view>
					<view class="action">
							<uni-icons type="arrowright" size="14" color="#999999"></uni-icons> 
					</view>
				</view>
				<view class="Photo">
					<view class="cell" @click="navigateTo('activity/lists?tab_index=1')">
						<view class="icon">
							<text class="iconfont">&#xe659;</text>
						</view>
						<view class="title">未开始</view>
					</view>
					<view class="cell" @click="navigateTo('activity/lists?tab_index=2')">
						<view class="icon">
							<text class="iconfont">&#xe604;</text>
						</view>
						<view class="title">进行中</view>
					</view>
					<view class="cell" @click="navigateTo('activity/lists?tab_index=3')">
						<view class="icon">
							<text class="iconfont">&#xe6f8;</text>
						</view>
						<view class="title">已结束</view>
					</view>
				</view>
			</view>
			
			
			<!--用户导航-->
			<view class="user-nav">
				<view class="nav-view user">
					<view class="cell" @click="navigateTo('orders/index')">
						<view class="icon">
							<image class="image" style="width: 32rpx;" src="../../../static/images/MYADDRESS@2x.png"></image>
						</view>
						<view class="title">我的订单</view>
					</view>
					<view class="cell" @click="navigateTo('favorites/index')">
						<view class="icon">
							<image class="image" src="../../../static/images/Collecting@2x.png"></image>
						</view>
						<view class="title">我的收藏</view>
					</view>
					<view class="cell" @click="navigateTo('history/index')">
						<view class="icon">
							<image class="image" src="../../../static/images/Cookies@2x.png"></image>
						</view>
						<view class="title">浏览记录</view>
					</view>
					
					<view class="cell" @click="navigateTo('config/index')">
						<view class="icon">
							<image class="image" src="../../../static/images/Setting@2x.png"></image>
						</view>
						<view class="title">设置</view>
					</view>
					<view class="cell" @click="openContact()">
						<view class="icon">
							<image class="image" src="../../../static/images/Service@2x.png"></image>
						</view>
						<view class="title">联系客服</view>
					</view>
				</view>
			</view>
			<template v-if="config">
				<CopyRight :config="config" />
			</template>
		</view>
		<!--自定义底部导航-->
		<tabBar :config="config" :footer="config.footer.data" />
		<!--登录框-->
		<Login ref="login" :config="config" @getUserInfo="getUserInfo"/>
		<!--联系客服popup弹窗-->
		<uni-popup ref="openContact" type="bottom">
			<view class="open-contact">
				<view class="header">联系客服</view>
				<view class="content">
					<view class="item contact">
						<view class="title">
							在线客服
						</view>
						<view class="info">
							<button open-type="contact" size="mini">打开客服会话</button>
						</view>
					</view>
					<view class="item qq" v-if="config.config.service.qq != undefined">
						<view class="title">
							QQ客服
						</view>
						<view class="info">
							<view class="">
								{{config.config.service.qq}}
							</view>
						</view>
					</view>
					<view class="item phone" v-if="config.config.service.mobile != undefined">
						<view class="title">
							服务热线
						</view>
						<view class="info">
							<view class="">
								{{config.config.service.mobile}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	import CopyRight from '../common/copyRight.vue' //自定义版权
	import TabBar from "../common/tabBar.vue" //底部导航
	export default {
		components: {
			CopyRight,
			TabBar,
		},
		data() {
			return {
				userInfo: {},
			}
		},
		async onLoad(option) {
			await this.$onLaunched;
			this.urlParams = option
		},
		created() {
			//设置原生导航栏
			this.setNavigation(this.config.style);
			this.getUserInfo()
		},
		onPullDownRefresh() {
			//console.log('refresh');
			this.getUserInfo()
		},
		computed: {
			...mapState(['config'])
		},
		methods: {

			login: function(){
				//触发登录框
				this.$refs.login.login()
			},
			/**
			 * 获取已登录用户数据
			 */
			getUserInfo: function(){
				let that = this
				this.util.getUserInfo((res)=>{
					console.log('userInfo',res)
					let userInfo = uni.getStorageSync('userInfo') || {}
					that.userInfo = userInfo
					that.getApiUserInfo()
				})
			},
			
			/**
			 * 获取用户详情数据
			 */
			getApiUserInfo: function(){
				let that = this
				let data = {}
					data.action = 'user_info'
					data.m = 'muu_activity'
				//动态获取用户数据
				let url = ''
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/ucenter'
					//#endif
					//#ifdef H5
					url = 'entry/site/ucenter'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							that.userInfo.sessionid = that.userInfo.sessionid
							that.userInfo.memberInfo = res.data.data
							uni.setStorageSync('userInfo', that.userInfo)
							console.log(that.userInfo)
						}
						//结束下拉刷新
						uni.stopPullDownRefresh();
					}
				})
			},
			
			navigateTo: function(page){
				let that = this
				let url = page
				console.log(url)
				let userInfo = uni.getStorageSync('userInfo') || {};
				if (userInfo.memberInfo != undefined) {
					uni.navigateTo({
						url: url
					});
				}else{
					this.login()
				}
			},
			
			/**
			 * 联系客服popup弹出
			 */
			openContact: function(){
				this.$refs.openContact.open()
			},
			setNavigation: function(style) {
				let that = this
				//动态更改顶部状态栏演示
				let backgroundColor = '#ffffff'
				//console.log(this.config)
				if(style == 'Green'){
					backgroundColor = '#00ce74';
				}
				if(style == 'Blue'){
					backgroundColor = '#03b8cf';
				}
				if(style == 'LightRed'){
					backgroundColor = '#ea644a';
				}
				if(style == 'Orange'){
					backgroundColor = '#ff9900';
				}
				if(style == 'LightPink'){
					backgroundColor = '#ffb6c1';
				}
				if(style == 'Magenta'){
					backgroundColor = '#8666b8';
				}
				//console.log(backgroundColor);
				//更改小程序原生导航栏
				uni.setNavigationBarColor({
					frontColor: '#ffffff',
					backgroundColor: backgroundColor,
				})
			}
		}
	}
</script>

<style lang="scss">

	page {
		background-color: #f8f8f8;
		min-height: 100%;
	}
	.main-section {
		background-color: #fff;
		.header {
			min-height: 180rpx;
			padding: 40rpx 40rpx 60rpx 40rpx;
            border-bottom-right-radius:750rpx 90rpx;
            border-bottom-left-radius:750rpx 90rpx;
			.config {
				color: #fff;
				text-align: right;
			}
			.user-info {
				color: #fff;
				display: flex;
				justify-content: left;
				.avatar {
					position: relative;
					width: 115rpx;
					height: 115rpx;
					border-radius: 50%;
					overflow: hidden;
					margin-right: 20rpx;
					// border: 6rpx solid #fff;
					overflow: hidden;
					z-index: 2;
					.image {
						width: 115rpx;
						height: 115rpx;
						display: block;
						z-index: 1;
					}
				}
				.right-info {
					display: block;
					margin-left: 20rpx;
					.nickname {
						width: 380rpx;
						line-height: 72rpx;
						font-size: 42rpx;
					}
					.uid {
						font-size: 24rpx;
					}
				}
			}
			.login {
				color: #fff;
				display: flex;
				justify-content: left;
				.avatar {
					width: 96rpx;
					height: 96rpx;
					border-radius: 50%;
					overflow: hidden;
					margin-right: 20rpx;
					.image {
						width: 96rpx;
						height: 96rpx;
					}
				}
				.login-btn {
					display: block;
					line-height: 96rpx;
					font-size: 28rpx;
				}
			}
		}
		.user-exp-info {
			position: relative;
			top: 20rpx;
			padding: 50rpx 0 10rpx;
			z-index: 10;
			display: flex;
			color: #666;
			margin-bottom: -40rpx;
			.wallet {
			    flex: 1;
			    padding: 20rpx 40rpx;
				.title {
					font-size: 24rpx;
					font-weight: 600;
					color: #DEFAFF;
					line-height: 33rpx;
					font-family: 'PingFangSC-Medium, PingFang SC';
					text-align: center;
				}
				.info {
					font-size: 36rpx;
					text-align: center;
					line-height: 50rpx;
					.credit {
						color: #fff;
						margin: 0 10rpx;
					}
				}
			}
			.checkin {
			    flex: 1;
			    padding: 20rpx 40rpx;
				.title {
					font-size: 24rpx;
					font-weight: 600;
					color: #DEFAFF;
					line-height: 33rpx;
					text-align: center;
					font-family: 'PingFangSC-Medium, PingFang SC';
				}
				.info {
					font-size: 36rpx;
					font-family: 'PingFangSC-Medium, PingFang SC';
					text-align: center;
					.credit {
						color: #fff;
						margin: 0 10rpx;
					}
				}
			}
		}
		.myOrder{
			width:100%;
			height: 278rpx;
			.indentbar{
				display: flex;
				padding: 20rpx;
				line-height: 68rpx;
				.part{
					border-left:4rpx solid #0dafcc ;
					margin: 20rpx 0;
					margin-right: 26rpx;
					border-radius:3rpx;
				}
				.indent{
					flex: 1;
					font-size: 32rpx;
					font-family: 'PingFangSC-Regular, PingFang SC';
					font-weight: 600;
					color: #000000;
				}
				.allorders{
					font-size: 24rpx;
					font-family: 'PingFangSC-Regular, PingFang SC';
					font-weight: 400;
					color: #909090;
					margin-right: 4rpx;
				}
				.action{
					width: 20rpx;
					margin-right: 35rpx;
				}
			}
			.Photo {
				margin-left: 4rpx;
				display: flex;
				.cell {
					flex: 1;
					text-align: center;
					margin-top: 30rpx;
					.title {
						flex: 1;
						font-size: 24rpx;
						color: #666;
						margin-top: 10rpx;
						font-family: "PingFangSC-Regular, PingFang SC";
					}
					.icon{
						width: 42rpx;
						height: 42rpx;
						margin: 0 auto;
						.iconfont{
							font-size: 42rpx;
					    }
					}
					
				}
			}
		}
		.user-nav {
			background-color: #f5f5f7;
			padding-top: 16rpx;
			.nav-view {
				position: relative;
				overflow: hidden;
				box-shadow: 0 2rpx 4rpx rgba(0,0,0,.05);
				background-color: #fff;
			}
			.cell {
				display: flex;
				padding: 22rpx 10rpx 22rpx 30rpx;
				line-height: 54rpx;
				.title {
					flex: 1;
					font-size: 32rpx;
					color: #000000;
					margin-left: 30rpx;
					font-weight: 600;
					font-family: "PingFangSC-Regular, PingFang SC";
				}
				.image{
					width: 40rpx;
					height: 40rpx;
					// margin-right: 30rpx;
				}
				.action {
					width: 36rpx;
				}
				&:active {
					background-color: #f2f2f2;
				}
			}
			.user {
				.icon {
					width: 48rpx;
				}
			}
		}
	}
	.open-contact {
		background-color: #fff;
		padding: 20rpx;
		.header {
			font-size: 30rpx;
			font-weight: 600;
			line-height: 64rpx;
			text-align: center;
			margin-bottom: 40rpx;
			
		}
		.content {
			.item {
				display: flex;
				margin-bottom: 16rpx;
				.title {
					width: 200rpx;
					font-size: 28rpx;
					color: #666;
				}
				.info {
					flex: 1;
					font-size: 28rpx;
					color: #666;
				}
			}
			.item.wechat {
				.info {
					.image {
						width: 200rpx;
						height: 200rpx;
						border: 2rpx solid #f8f8f8;
					}
				}
			}
		}
	}
	
	.Blue {
		.main-section {
			.header {
				background-color: $Blue;
			}
			.myOrder {
				.part{
					border-left:4rpx solid $Blue;
				}
				.Photo {
					.icon {
						color: $Blue;
					}
				}
			}
			
		}
	}
	
	.Green {
		.main-section {
			.header {
				background-color: $Green;
			}
			.myOrder {
				.part{
					border-left:4rpx solid $Green;
				}
				.Photo {
					.icon {
						color: $Green;
					}
				}
			}
		}
	}
	
	.LightRed {
		.main-section {
			.header {
				background-color: $LightRed;
			}
			.myOrder {
				.part{
					border-left:4rpx solid $LightRed;
				}
				.Photo {
					.icon {
						color: $LightRed;
					}
				}
			}
		}
	}
	
	.Orange {
		.main-section {
			.header {
				background-color: $Orange;
			}
			.myOrder {
				.part{
					border-left:4rpx solid $Orange;
				}
				.Photo {
					.icon {
						color: $Orange;
					}
				}
			}
		}
	}
	
	.LightPink {
		.main-section {
			.header {
				background-color: $LightPink;
			}
			.myOrder {
				.part{
					border-left:4rpx solid $LightPink;
				}
				.Photo {
					.icon {
						color: $LightPink;
					}
				}
			}
		}
	}
	
	.Magenta {
		.main-section {
			.header {
				background-color: $Magenta;
			}
			.myOrder {
				.part{
					border-left:4rpx solid $Magenta;
				}
				.Photo {
					.icon {
						color: $Magenta;
					}
				}
			}
		}
	}

</style>
